
App({
  onLaunch: function () {
    qq.showShareMenu({
      showShareItems: ['qq', 'qzone', 'wechatFriends', 'wechatMoment']
    })
    var that = this
    this.getAccessToken()
    var ms = (61 - new Date().getMinutes()) * 60000
    setTimeout(function () {
      that.getAccessToken()
      setInterval(function () {
        that.getAccessToken()
      }, 3600000)
    }, ms)
  // //console.log(ms)
    this.getUserInfo()
    try {
      //console.log('s')
      const value = qq.getStorageSync('openid')
      //console.log(value)
      if (value) {
        //console.log(value)
        that.globalData.openid = value
      } else {
        qq.login({////////////调用qq登录获取code
          success(res) {
            that.getOpenID(res.code)
          },
        })
      }
    } catch (e) {
      //console.log(e)
      //console.log("d")
    }
  },
  getUserInfo() {
    qq.getSetting({
      success(res) {
        // //console.log(res)
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称
          qq.getUserInfo({
            success(res) {
              // //console.log(res.userInfo)
            }
          })
        }
      }
    })
  },
  getOpenID(code) {
    //console.log(code)
    var that = this
    wx.request({
      url: 'https://service-pvyg928b-1257796010.ap-beijing.apigateway.myqcloud.com/release/getOpenID/' + code,//部署在腾讯云函数上的
      header: {
        'content-type': 'application/json' // 默认值
      },
      method: "post",
      success(res) {
        //console.log(res)
        that.globalData.openid = res.data
        qq.setStorage({
          key: 'openid',
          data: res.data
        })
      }
    })
  },
  getAccessToken() {
    console.log("d")
    var that = this
    qq.request({
      url: 'https://service-1fypo9xh-1257796010.ap-beijing.apigateway.myqcloud.com/release/getToken',//部署在腾讯云函数上的
      header: {
        'content-type': 'application/json' // 默认值
      },
      method: "post",
      success(res) {
        //console.log("token" + res.data)
        that.globalData.access_token = res.data
      }
    })
  },
  globalData: {
    myEnv: 'test2-biqte',
    openid: '',
    access_token: '',
    userInfo: null,
    admin: false
  }
})
